Repository navigation
Conversation
`get_option()` and `get_site_option()` return the default both when an option does not exist and when their query fails, and cache the option as missing either way. `WP_Secrets_Option_Store::get()` read that as an absent secret, so during a failed read `wp_get_secret()` returned `null` for a stored secret and `wp_set_secret()` treated it as new, writing a record with no previous version. When the Options API returns the default, the store now checks the database directly. If the row exists, it returns the record and clears the cached "missing" entry. If that read fails too, it returns a `secret_store_unavailable` error, which the write path already treats as fatal. `WP_Secrets_Option_Store::delete()` now uses the same check, so it no longer reports success when it cannot tell whether the record still exists. See #66424.
Adds tests that read a network secret back after the cache is flushed, which catches a second `wp_sitemeta` row left by writing through a stale "missing" cache entry. A row with an empty or `NULL` value now reports `secret_record_malformed` rather than reading as an absent secret. See #66424.
…re-failed-read # Conflicts: # src/wp-includes/secrets/class-wp-secrets-option-store.php
wpdb::get_col() returns an empty array when its query fails, so the is_array() check in WP_Secrets_Option_Store::list_names() could never fire, and a failed listing read as no secrets. Failure is now taken from wpdb::query(), as get() does.
…ntions. Adds a summary, @Covers annotations and a unique failure message to each test, as r65272 did for the existing Secrets API tests. Asserts the result of every setup write, and uses the multisite group and skipWithoutMultisite() for the multisite-only test. Also adds a test for a failed listing in WP_Secrets_Option_Store::list_names().
…s result. wpdb::get_var() and wpdb::get_col() are called without a query, to read the result of the prepared query that wpdb::query() just ran. PHPCS reads that as an unprepared query.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…filters. See #66424.
Takes over #15329 by @MicahelE, which conflicts with trunk and hasn't been updated since the review on 6 November. MicahelE's two commits are unchanged. Trunk is merged in, and three commits of mine on top make the changes requested on the ticket and in review.
What changes
From #15329 (MicahelE):
get_option()orget_site_option()returns the default,WP_Secrets_Option_Store::get()reads the row directly:null.secret_store_unavailable, which the write path already treats as fatal.update_site_option()goes throughadd_network_option(), which inserts a secondwp_sitemetarow, and later requests read the old one.delete()uses the same check, so it no longer reports success when it can't tell whether the record still exists.NULLvalue is a malformed record, not an absent one.wp_sitemeta.meta_valueis nullable. This case came from @dhrupo on Secrets: Tell a failed record read apart from a missing secret. #15301.Failure is taken from the return value of
wpdb::query(), becausewpdb::$last_erroris not set on every failure path. When the connection is lost,flush()clears it.Mine:
list_names()reports a failed query (requested in comment:4).wpdb::get_col()returns an empty array when its query fails, so theis_array()check could never fire. A failed listing madewp_list_secrets()show no secrets, and the Site Health check that keeps undecryptable records visible saw nothing. It now takes failure fromwpdb::query(), asget()does.@coversand a unique message on every assertion. Every setup write is asserted, and the multisite-only test uses themultisitegroup andskipWithoutMultisite(). There's also a new test for the failed listing.get_var()andget_col()called without a query, which read the result of the prepared query before them.Not changed:
WP_Secrets_Key_Manager::forget_missing_root_key(), which does the same for the root key. Both are private, and sharing one would mean a new internal function. A committer can merge them on commit, as the ticket discussion suggested.secrets.php.Testing
--group 66424: 14 tests on single site and 15 on multisite. With trunk'sclass-wp-secrets-option-store.php, every one fails.--group secrets: 448 tests on single site and 457 on multisite, no failures (PHP 8.5, trunk at r65404).--group option: 446 tests, no failures.Trac ticket: https://core.trac.wordpress.org/ticket/66424
Props MicahelE, dhrupo.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: The original commits were written with Claude Code, as noted on #15329. For this takeover: the trunk merge, the
list_names()change, the test updates and this description. I reviewed the changes and the results.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.